<template>
  <div>
    <div class="address_select">
      <v-distpicker province="河南省" city="濮阳市" area="南乐县"></v-distpicker>
      <el-button style="margin-left: 20px">查询</el-button>
    </div>
    <div style="display:flex">
      <div id="age_chart"></div>
      <div id="work_chart"></div>
      <div id="float_chart"></div>
    </div>
    <div>
      <div id="field_chart"></div>
    </div>
  </div>
</template>

<script>
import VDistpicker from 'v-distpicker'
import echarts from 'echarts/lib/echarts'
import 'echarts/lib/chart/bar'
import 'echarts/lib/component/title'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/pie'
import 'echarts/lib/component/legend'
import 'echarts/lib/chart/funnel'
export default {
  components: {
    VDistpicker: VDistpicker
  },
  methods: {
    initAgeChart () {
      const myChart = echarts.init(document.getElementById('age_chart'))
      const option = {
        title: {
          text: '南乐县乡村劳动力年龄分布'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        xAxis: [
          {
            type: 'category',
            data: ['20-25', '25-30', '30-35', '35-40', '40-45', '45-50', '50-55', '55-60'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [{ type: 'value' }],
        series: [
          {
            name: '劳动力人数',
            type: 'bar',
            barWidth: '60%',
            data: [995, 666, 444, 858, 566, 678, 520, 821]
          }
        ],
        grid: {
          top: 50,
          x: 45,
          y: 45,
          x2: 30,
          y2: 30
        }
      }
      myChart.setOption(option)
      // 建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
      window.addEventListener('resize', function () { myChart.resize() })
    },
    initWorkChart () {
      const myChart = echarts.init(document.getElementById('work_chart'))
      const option = {
        title: {
          text: '就业形式'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['20-30岁', '30-40岁', '40-50岁', '50-60岁']
        },
        xAxis: [
          {
            type: 'category',
            data: ['2017', '2018', '2019', '2020']
          }
        ],
        yAxis: [{ type: 'value' }],
        series: [
          {
            name: '20-30岁',
            type: 'line',
            smooth: true,
            stack: '总量',
            data: [321, 456, 800, 300]
          },
          {
            name: '30-40岁',
            type: 'line',
            smooth: true,
            stack: '总量',
            data: [400, 600, 681, 389]
          },
          {
            name: '40-50岁',
            type: 'line',
            smooth: true,
            stack: '总量',
            data: [200, 328, 561, 100]
          },
          {
            name: '50-60岁',
            type: 'line',
            smooth: true,
            stack: '总量',
            data: [100, 300, 590, 50]
          }
        ],
        grid: {
          top: 50,
          x: 45,
          y: 45,
          x2: 30,
          y2: 30
        }
      }
      myChart.setOption(option)
      // 建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
      window.addEventListener('resize', function () { myChart.resize() })
    },
    initFloatChart () {
      const myChart = echarts.init(document.getElementById('float_chart'))
      const option = {
        title: {
          text: '南乐县乡村劳动力就业流动情况'
        },
        series: [
          {
            name: '劳动力人数',
            type: 'pie',
            smooth: true,
            data: [
              { value: 800, name: '县城工作' },
              { value: 400, name: '市区工作' },
              { value: 200, name: '跨市区工作' },
              { value: 600, name: '跨省工作' }
            ]
          }
        ]
      }
      myChart.setOption(option)
      // 建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
      window.addEventListener('resize', function () { myChart.resize() })
    },
    initFieldChart () {
      const myChart = echarts.init(document.getElementById('field_chart'))
      const option = {
        title: {
          text: '就业领域'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c}%'
        },
        toolbox: {
          feature: {
            dataView: { readOnly: false },
            restore: {},
            saveAsImage: {}
          }
        },
        legend: {
          data: ['餐饮', '出租', '建筑', '教育', '中介', '物业', '互联网', '邮政/快递', '矿产/采掘', '卫生服务', '旅游']
        },
        series: [
          {
            name: '漏斗图',
            type: 'funnel',
            left: '5%',
            top: 60,
            bottom: 30,
            width: '90%',
            height: '80%',
            min: 0,
            max: 100,
            minSize: '0%',
            maxSize: '100%',
            sort: 'descending',
            gap: 2,
            label: {
              show: true,
              position: 'inside'
            },
            labelLine: {
              length: 10,
              lineStyle: {
                width: 1,
                type: 'solid'
              }
            },
            itemStyle: {
              borderColor: '#fff',
              borderWidth: 1
            },
            emphasis: {
              label: {
                fontSize: 20
              }
            },
            data: [
              { value: 160, name: '餐饮' },
              { value: 20, name: '出租' },
              { value: 290, name: '建筑' },
              { value: 100, name: '教育' },
              { value: 60, name: '中介' },
              { value: 80, name: '物业' },
              { value: 30, name: '互联网' },
              { value: 130, name: '邮政/快递' },
              { value: 51, name: '矿产/采掘' },
              { value: 200, name: '卫生服务' },
              { value: 180, name: '旅游' }
            ]
          }
        ]
      }
      myChart.setOption(option)
      // 建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
      window.addEventListener('resize', function () { myChart.resize() })
    }
  },
  mounted () {
    this.initAgeChart()
    this.initWorkChart()
    this.initFloatChart()
    this.initFieldChart()
  }
}
</script>

<style lang="less" scoped>
#age_chart{
  width: 30%;
  height: 270px;
  margin: 10px 10px;
  background-color: white;
}
#work_chart{
  width: 50%;
  height: 270px;
  margin: 10px 10px;
  background-color: white;
}
#float_chart{
  width: 30%;
  height: 270px;
  margin: 10px 10px;
  background-color: white;
}
#field_chart{
  width: 98.5%;
  height: 400px;
  margin: 10px 10px;
  background-color: white;
}
.address_select{
  width: 700px;
  line-height: 40px;
  display: flex;
}
.trend{
  line-height: 40px;
  text-align: left;
}
.introduce{
  line-height: 40px;
  text-align: left;
}
</style>
